package com.db.controller;

import com.db.common.pojo.PageObject;
import com.db.pojo.SysRole;
import com.db.service.SysRoleService;
import com.db.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role/")
public class SysRoleController {

	@Autowired
	private SysRoleService sysRoleService;

	@RequestMapping("doFindPageObjects")
	public SysResult doFindPageObjects(String username, Integer pageCurrent) {
		PageObject<SysRole> list = sysRoleService.findObjects(username, pageCurrent);
		return new SysResult(list);
	}

	@RequestMapping("doDeleteObject")
	public SysResult doDeleteObject(Integer id) {
		sysRoleService.deleteById(id);
		return new SysResult("delete ok");
	}

	@RequestMapping("doSaveObject")
	public SysResult doSaveObject(SysRole sysRole, Integer... menuIds) {
		sysRoleService.saveObject(sysRole, menuIds);
		return new SysResult("save ok");
	}

	@RequestMapping("doFindObjectById")
	public SysResult doFindObjectById(Integer id) {
		Map<String, Object> sysRole = sysRoleService.findById(id);
		return new SysResult(sysRole);
	}

	@RequestMapping("doUpdateObject")
	public SysResult doUpdateObject(SysRole sysRole, Integer... menuIds) {
		sysRoleService.updateObjects(sysRole, menuIds);
		return new SysResult("save ok");
	}


	@RequestMapping("doFindRoles")
	public SysResult doFindRoles() {
		List<SysRole> sysRoles = sysRoleService.findRoleIdName();
		return new SysResult(sysRoles);
	}
}
